<?php

/**
 * 需求截止时间、投标人数已满后，自动已完成
 */
namespace App\Console\Commands;

use App\Models\Demands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class DemandTimingTask extends Command
{
    protected $name = 'demand_timing_task';//命令名称

    public function handle()
    {
        //需求截止时间小于当天、投标人数已满的，状态改为已完成
        Log::info('demand_timing_task running');
        $demands = Demands::where('status',1)->get(['id','end_at','number','limit_num','is_can']);
        foreach ($demands as $key => $val) {
            if (($val['number'] == $val['limit_num']) || (trim(@date('Y-m-d', strtotime($val['end_at']))) < date('Y-m-d'))){
                Demands::where('id',$val['id'])->update(["is_can"=>2]);
            }
        }
    }
}